package cn.javasm.common.page;

import lombok.*;

/**
 * @author: Lisa
 * @className: PageInfo
 * @description:
 * @date: 2023/10/25 20:51
 * @VERSION: 0.1
 * @SINCE: jdk11
 */
@Getter
@Setter
@ToString
@NoArgsConstructor
public class PageInfo {
    Integer page;
    Integer pageSize;
    Integer total;

    public PageInfo(Integer page, Integer pageSize, Integer total) {
        this.page = page;
        this.pageSize = pageSize;
        this.total = total;
    }

    public static Integer changePage(Integer total, Integer page, Integer pageSize) {
        Integer totalPage;
        totalPage = total % pageSize == 0 ? total / pageSize : (total / pageSize) + 1;
        if (totalPage != 0) {
            if (page > totalPage) {
                page = totalPage;
            }
        } else {
            page = 1;
        }


        System.out.println("page超过最大页数时 把page改成最大页");
        System.out.println(page);
        return page;
    }
}
